<!-- 发送文本 -->
<script setup>
import { ActionSheet, Button } from 'vant';
import { ref } from 'vue';

const props = defineProps({
    show: Boolean,
    callback: Function,
})

const isShow = ref(props.show)
const sendText = ref('')

const onSendText = () => {
    if (!sendText.value || sendText.value.length <= 0) {
        return
    }
    const text = encodeURIComponent(sendText.value)
    fetch(`/api/file/text?content=${text}`)
        .then(response => response.json())
        .then(data => props.callback(data.code === 0, data))
        .catch(err => props.callback(false, err));
}

</script>

<template>
    <ActionSheet v-model:show="isShow" title="共享文本（如某多链接...）">
        <div style="padding: 10px;">
            <textarea v-model="sendText" rows="5"
                style="width: 100%; box-sizing: border-box; padding: 10px; border-radius: 10px;"
                placeholder="在这里键入文本...">
            </textarea>
            <Button @click="onSendText" type="success" block style="margin: 10px 0;">确认发送</Button>
        </div>
    </ActionSheet>
</template>

<style lang="scss" scoped>

</style>